package com.hnjfzn.common.core.utils;

import java.security.SecureRandom;

public class SaltUtil {
    private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final int SALT_LENGTH = 8;

    public static String generateSalt() {
        SecureRandom random = new SecureRandom();
        StringBuilder salt = new StringBuilder("$1$");  // 确保以 "$1$" 开头

        for (int i = 0; i < SALT_LENGTH; i++) {
            int index = random.nextInt(CHARACTERS.length());
            salt.append(CHARACTERS.charAt(index));
        }

        return salt.toString();  // 返回完整的盐值
    }
}
